package Presentacion.academico;

import CapaDatos.Sql;
import clases.general.Ciudad;
import global.Dialogos;
import global.Iconos;
import java.awt.Image;
import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

public final class dlgAlumno extends javax.swing.JDialog {

    public JFileChooser ventana = new JFileChooser();
    public Icon icono;
    public String ruta;
    private Iconos ico = new Iconos();

    /**
     * Creates new form dlgAlumno
     *
     * @param parent
     * @param modal
     */
    public dlgAlumno(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setResizable(false);
        setTitle("REGISTRO DE ALUMNO");
        setLocationRelativeTo(this);
        iconos();
        frmConsultaAlumno.objAlumno.comboCiudad(cbociudad);
        limpiarAlumno();
    }

    private void iconos() {
        btnnuevo.setIcon(ico.getNuevo());
        btnguardar.setIcon(ico.getGuardar());
        btnsalir.setIcon(ico.getSalir());
        btnactualizar.setIcon(ico.getActualizar());
    }

    public void llenardatosAlumno() {
        txtcedula.setEditable(false);
        txtcedula.setText(frmConsultaAlumno.objAlumno.getCedulaRuc());
        txtnombres.setText(frmConsultaAlumno.objAlumno.getNombre());
        txtapellido.setText(frmConsultaAlumno.objAlumno.getApellido());
        txtdireccion.setText(frmConsultaAlumno.objAlumno.getDireccion());
        txttelefono.setText(frmConsultaAlumno.objAlumno.getTelefono());
        cbociudad.setSelectedItem(frmConsultaAlumno.objAlumno.getCiudad());
        txtlugarnacimiento.setText(frmConsultaAlumno.objAlumno.getLugarnacimiento());
        txtcorreo.setText(frmConsultaAlumno.objAlumno.getCorreo());
        cbogenero.setSelectedItem(frmConsultaAlumno.objAlumno.getGenero());
        dtfechanaci.setDate(global.Util.StringaDate(frmConsultaAlumno.objAlumno.getFechanacimiento()));

        if (frmConsultaAlumno.objAlumno.ExistenciaFotoAlumno() == true) {
            icono = new ImageIcon(Sql.getfoto("SELECT FOTO FROM ALUMNO WHERE CEDULARUC='" + frmConsultaAlumno.objAlumno.getCedulaRuc() + "'"
            ).getScaledInstance(lblfoto.getWidth(), lblfoto.getHeight(), Image.SCALE_DEFAULT));
            lblfoto.setText("");
            lblfoto.setIcon(icono);
        } else {
            lblfoto.setText("FOTO");
        }
    }

    public void limpiarAlumno() {
        txtnombres.requestFocus();
        txtcedula.setEditable(true);
        txtcedula.setText("");
        txtapellido.setText("");
        txtdireccion.setText("");
        txtnombres.setText("");
        txtlugarnacimiento.setText("");
        txttelefono.setText("");
        cbociudad.setSelectedIndex(0);
        txtcorreo.setText("");
        cbogenero.setSelectedIndex(0);
        lblfoto.setText("Foto");
        dtfechanaci.setDate(global.Util.StringaDate(global.Util.getFechaActual()));
        lblfoto.setIcon(null);
        ruta = "";
        txtcedula.requestFocus();
        visiblidad(true);
    }

    private boolean Valadicaion() {
        if ("".equals(txtcedula.getText())) {
            Dialogos.FaltaCampo("Cedula");
            txtcedula.requestFocus();
            return false;
        } /*else if (global.Validaciones.validarCedula(txtcedula.getText()) == false) {
         global.Mensajes.mostrarMensaje("Error", "Cedula incorrecta", 3);
         txtcedula.requestFocus();
         return false;

         }*/ else if ("".equals(txtnombres.getText())) {
            Dialogos.FaltaCampo("Nombres");
            txtnombres.requestFocus();
            return false;
        } else if ("".equals(txtapellido.getText())) {
            Dialogos.FaltaCampo("Apellidos");
            txtapellido.requestFocus();
            return false;
        } else if ("".equals(txtlugarnacimiento.getText())) {
            Dialogos.FaltaCampo("Lugar Nacimiento");
            txtlugarnacimiento.requestFocus();
            return false;
        } else if ("".equals(txtcorreo.getText())) {
            Dialogos.FaltaCampo("Correo");
            txtcorreo.requestFocus();
            return false;
        } else if ("".equals(txtdireccion.getText())) {
            Dialogos.FaltaCampo("Direccion");
            txtdireccion.requestFocus();
            return false;
        } else if ("".equals(txttelefono.getText())) {
            Dialogos.FaltaCampo("Telefono");
            txttelefono.requestFocus();
            return false;
        } else if (cbogenero.getSelectedIndex() == 0) {
            Dialogos.FaltaCampo("Genero");
            cbogenero.requestFocus();
            return false;
        } else if ("--Seleccione--".equals(cbociudad.getSelectedItem())) {
            Dialogos.FaltaCampo("Ciudad");
            cbociudad.requestFocus();
            return false;
        } else {
            return true;
        }

    }

    public void visiblidad(boolean visibilidad) {
        if (visibilidad != true) {
            btnactualizar.setVisible(true);
            btnguardar.setVisible(false);
        } else {
            btnactualizar.setVisible(false);
            btnguardar.setVisible(true);
        }
    }

    private void set() {
        frmConsultaAlumno.objAlumno.setCedulaRuc(txtcedula.getText());
        frmConsultaAlumno.objAlumno.setNombre(txtnombres.getText());
        frmConsultaAlumno.objAlumno.setApellido(txtapellido.getText());
        frmConsultaAlumno.objAlumno.setTelefono(txttelefono.getText());
        frmConsultaAlumno.objAlumno.setDireccion(txtdireccion.getText());
        frmConsultaAlumno.objAlumno.setCiudad(cbociudad.getSelectedItem().toString());
        frmConsultaAlumno.objAlumno.setLugarnacimiento(txtlugarnacimiento.getText());
        frmConsultaAlumno.objAlumno.setGenero(cbogenero.getSelectedItem().toString());
        frmConsultaAlumno.objAlumno.setFechanacimiento(global.Util.DateaString(dtfechanaci.getDate()));
        frmConsultaAlumno.objAlumno.setCorreo(txtcorreo.getText().toLowerCase());
    }

    private void insertarFoto() {
        if (!ruta.equals("")) {
            Sql.insertarFoto("UPDATE ALUMNO SET FOTO=? WHERE CEDULARUC='" + frmConsultaAlumno.objAlumno.getCedulaRuc()
                    + "'", ruta);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PanelAlumno = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtcedula = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtnombres = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        lblfoto = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtapellido = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txttelefono = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        dtfechanaci = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtcorreo = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        cbogenero = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        cbociudad = new javax.swing.JComboBox();
        txtlugarnacimiento = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        btnexaminar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtdireccion = new javax.swing.JTextArea();
        btnciudad = new javax.swing.JButton();
        jToolBar4 = new javax.swing.JToolBar();
        btnnuevo = new javax.swing.JButton();
        btnguardar = new javax.swing.JButton();
        btnactualizar = new javax.swing.JButton();
        btnsalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        PanelAlumno.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("CEDULA");

        txtcedula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtcedulaFocusLost(evt);
            }
        });
        txtcedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtcedulaKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("NOMBRES");

        txtnombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtnombresKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtnombresKeyTyped(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblfoto.setBackground(new java.awt.Color(255, 255, 255));
        lblfoto.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblfoto.setText("FOTO");
        lblfoto.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblfoto, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblfoto, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("APELLIDOS");

        txtapellido.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtapellidoKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtapellidoKeyTyped(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("TELÉFONO");

        txttelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txttelefonoKeyTyped(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("FECHA NACIMIENTO");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("DIRECCIÓN");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("CORREO");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel15.setText("GÉNERO");

        cbogenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Seleccione--", "MASCULINO", "FEMENINO" }));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("CIUDAD");

        txtlugarnacimiento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtlugarnacimientoKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtlugarnacimientoKeyTyped(evt);
            }
        });

        jLabel28.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel28.setText("LUGAR NACIMIENTO");

        btnexaminar.setText("Examinar");
        btnexaminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnexaminarActionPerformed(evt);
            }
        });

        txtdireccion.setColumns(20);
        txtdireccion.setRows(5);
        txtdireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtdireccionKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(txtdireccion);

        btnciudad.setText("+");
        btnciudad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnciudadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PanelAlumnoLayout = new javax.swing.GroupLayout(PanelAlumno);
        PanelAlumno.setLayout(PanelAlumnoLayout);
        PanelAlumnoLayout.setHorizontalGroup(
            PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelAlumnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel10)
                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(54, 54, 54)
                        .addComponent(txtapellido))
                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel28)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dtfechanaci, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelAlumnoLayout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtcorreo, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtlugarnacimiento)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)))))
                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1))
                        .addGap(62, 62, 62)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtnombres, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtcedula, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(134, 134, 134)
                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PanelAlumnoLayout.createSequentialGroup()
                                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                                        .addGap(19, 19, 19)
                                        .addComponent(btnexaminar))
                                    .addComponent(txttelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(cbociudad, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbogenero, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnciudad))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, PanelAlumnoLayout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PanelAlumnoLayout.setVerticalGroup(
            PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelAlumnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtcedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtnombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtapellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtlugarnacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel28)))
                    .addGroup(PanelAlumnoLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnexaminar)))
                .addGap(25, 25, 25)
                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(dtfechanaci, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txttelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)))
                    .addComponent(jLabel11))
                .addGap(25, 25, 25)
                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jLabel10)
                    .addComponent(txtcorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbogenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cbociudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)
                        .addComponent(jLabel7)
                        .addComponent(btnciudad))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jToolBar4.setBorder(null);
        jToolBar4.setFloatable(false);
        jToolBar4.setBorderPainted(false);

        btnnuevo.setText("Nuevo");
        btnnuevo.setFocusable(false);
        btnnuevo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnnuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnnuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnnuevoActionPerformed(evt);
            }
        });
        jToolBar4.add(btnnuevo);

        btnguardar.setText("Guardar");
        btnguardar.setFocusable(false);
        btnguardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnguardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnguardarActionPerformed(evt);
            }
        });
        jToolBar4.add(btnguardar);

        btnactualizar.setText("Actualizar");
        btnactualizar.setFocusable(false);
        btnactualizar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnactualizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnactualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnactualizarActionPerformed(evt);
            }
        });
        jToolBar4.add(btnactualizar);

        btnsalir.setText("Salir");
        btnsalir.setFocusable(false);
        btnsalir.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnsalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnsalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsalirActionPerformed(evt);
            }
        });
        jToolBar4.add(btnsalir);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar4, javax.swing.GroupLayout.DEFAULT_SIZE, 824, Short.MAX_VALUE)
                    .addComponent(PanelAlumno, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(3, 3, 3)
                .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PanelAlumno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtcedulaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtcedulaFocusLost

    }//GEN-LAST:event_txtcedulaFocusLost

    private void txtcedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtcedulaKeyTyped
        global.Validaciones.soloNumeros(evt, txtcedula, 10);
    }//GEN-LAST:event_txtcedulaKeyTyped

    private void txtnombresKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtnombresKeyReleased
        global.Validaciones.convertirMayuscula(txtnombres);
    }//GEN-LAST:event_txtnombresKeyReleased

    private void txtnombresKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtnombresKeyTyped
        global.Validaciones.soloLetras(evt, txtnombres);
    }//GEN-LAST:event_txtnombresKeyTyped

    private void txtapellidoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtapellidoKeyReleased
        global.Validaciones.convertirMayuscula(txtapellido);
    }//GEN-LAST:event_txtapellidoKeyReleased

    private void txtapellidoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtapellidoKeyTyped
        global.Validaciones.soloLetras(evt, txtapellido);
    }//GEN-LAST:event_txtapellidoKeyTyped

    private void txttelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txttelefonoKeyTyped
        global.Validaciones.soloNumeros(evt, txttelefono, 10);
    }//GEN-LAST:event_txttelefonoKeyTyped

    private void txtlugarnacimientoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtlugarnacimientoKeyReleased
        global.Validaciones.convertirMayuscula(txtlugarnacimiento);
    }//GEN-LAST:event_txtlugarnacimientoKeyReleased

    private void txtlugarnacimientoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtlugarnacimientoKeyTyped
        global.Validaciones.soloLetras(evt, txtlugarnacimiento);
    }//GEN-LAST:event_txtlugarnacimientoKeyTyped

    private void btnexaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnexaminarActionPerformed
        int resultado;

        FileNameExtensionFilter filtro = new FileNameExtensionFilter("JPG", "jpg");
        ventana.setFileFilter(filtro);
        resultado = ventana.showOpenDialog(lblfoto);

        if (JFileChooser.APPROVE_OPTION == resultado) {
            File foto = ventana.getSelectedFile();
            try {
                ImageIcon icon = new ImageIcon(foto.toString());
                icono = new ImageIcon(icon.getImage().getScaledInstance(lblfoto.getWidth(), lblfoto.getHeight(), Image.SCALE_SMOOTH));
                lblfoto.setText(null);
                lblfoto.setIcon(icono);
                ruta = ventana.getSelectedFile().getAbsolutePath();
            } catch (Exception ex) {
                global.Mensajes.mostrarMensaje("Error", "Error abriendo la imagen " + ex, 3);

            }
        }

    }//GEN-LAST:event_btnexaminarActionPerformed

    private void btnnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnuevoActionPerformed
        //   matricula.dlgMatriculacion.limpiarTodo();
        //   matricula.visibilidad();
        //   setVisible(true);
        limpiarAlumno();

    }//GEN-LAST:event_btnnuevoActionPerformed

    private void btnsalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsalirActionPerformed
        dispose();
        limpiarAlumno();
        // matricula.dlgMatriculacion.limpiarTodo();
    }//GEN-LAST:event_btnsalirActionPerformed

    private void btnciudadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnciudadActionPerformed
        String ciudad = "";
        ciudad = global.Dialogos.mostrarDialogoconTexto("AGREGAR CIUDAD", null);
        if (ciudad != null && !"".equals(ciudad)) {
            Ciudad objCiudad = new Ciudad();
            objCiudad.setNombreCiudad(ciudad.toUpperCase());
            if (objCiudad.guardarCiudad() == true) {
                cbociudad.addItem(ciudad.toUpperCase());
            }
        }
    }//GEN-LAST:event_btnciudadActionPerformed

    private void txtdireccionKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdireccionKeyReleased
        // global.Validaciones.convertirMayuscula(txtdireccion);
    }//GEN-LAST:event_txtdireccionKeyReleased

    private void btnactualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnactualizarActionPerformed
        if (Valadicaion() == true) {
            set();
            if (frmConsultaAlumno.objAlumno.actualizarAlumno() == true) {
                this.insertarFoto();
                frmConsultaAlumno.generartabla();
                dispose();
                limpiarAlumno();
            }

        }
    }//GEN-LAST:event_btnactualizarActionPerformed

    private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
        if (Valadicaion() == true) {
            set();
            if (frmConsultaAlumno.objAlumno.guardarAlumno() == true) {
                insertarFoto();
                limpiarAlumno();
                frmConsultaAlumno.generartabla();
            }
        }

    }//GEN-LAST:event_btnguardarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(dlgAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(dlgAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(dlgAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                dlgAlumno dialog = new dlgAlumno(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelAlumno;
    private javax.swing.JButton btnactualizar;
    private javax.swing.JButton btnciudad;
    private javax.swing.JButton btnexaminar;
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnnuevo;
    private javax.swing.JButton btnsalir;
    public static javax.swing.JComboBox cbociudad;
    public javax.swing.JComboBox cbogenero;
    public com.toedter.calendar.JDateChooser dtfechanaci;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar4;
    public javax.swing.JLabel lblfoto;
    public javax.swing.JTextField txtapellido;
    public javax.swing.JTextField txtcedula;
    public javax.swing.JTextField txtcorreo;
    public javax.swing.JTextArea txtdireccion;
    public javax.swing.JTextField txtlugarnacimiento;
    public javax.swing.JTextField txtnombres;
    public javax.swing.JTextField txttelefono;
    // End of variables declaration//GEN-END:variables
}
